<?php
/**
 * Description: 检查退款详情
 *
 * @author      Eden
 * @datetime    2016/12/20 11:04
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */

class Postage_Model extends API_Model
{

    /**
     * 初始化
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function run($params = array())
    {
        $send['state'] = true;
        do {

            $default = array(
                'payer' => 'seller',
                'costs' => new stdClass()
            );
            // 前期只考虑到统一的价格的情况,没有进行区域区分
            $db = clone($this->db);
            $q = $db->get_where('express_template', array('using' => 1));
            $row = $q->row_array();
            if (!$row) {
                $send['data'] = $default;
                break;
            }

            if ($row['payer'] == 'seller') {
                $send['data'] = $default;
                break;
            }

            $payer = $row['payer'];
            if ($row['payType'] == 'weight') {
                $q = $this->db->get_where('express_weight', array('tmpId' => $row['id']));
                $row = $q->row_array();
                if (empty($row)) {
                    $send['data'] = $default;
                    break;
                }
                $default['payer'] = $payer;
                $default['costs'] = array(
                    'firstWeight' => doubleval($row['firstWeight']),
                    'firstCost' => doubleval($row['firstCost']),
                    'incrWeight' => doubleval($row['incrWeight']),
                    'incrCost' => doubleval($row['incrCost'])
                );
            }
            
            $send['data']  = $default;
        } while(false);
        $this->output->send($send);
    }

}
